﻿using AiShow.BLL;
using AiShow.IBLL;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AiShow.WebSite
{
    // <summary>
    /// 评论列表处理程序
    /// </summary>
    public class DiscussListHandler : IHttpHandler
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            // 取值
            string videoId = context.Request.QueryString["id"];
            int pageNumber = int.Parse(context.Request.QueryString["pageNumber"]);
            int pageSize = int.Parse(context.Request.QueryString["pageSize"]);
            // 读取列表
            IDiscussManager discussManager = new DiscussManager();
            List<Model.Discuss> discusses = discussManager.QueryDiscusses(videoId, pageNumber, pageSize);
            // 返回结果
            string discussesJson = JsonConvert.SerializeObject(discusses, new UnixDateTimeConverter());
            //context.Response.ContentType = "text/plain";
            context.Response.ContentType = "application/Json";
            context.Response.Write(discussesJson);
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}